<template>
    <div class="sidebar">
       <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" background-color="#2b3c53" text-color="#fff" theme="dark" unique-opened router>
            <template v-for="item in items" >
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.id">
                        <template slot="title" class="menu-left"><i :class="item.icon"></i>{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">{{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.id">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
export default {
  data () {
    return {
      items: [
        {
          icon: 'el-icon-setting',
          index: '123',
          title: '我的课程面板'
        },
        {
          icon: 'el-icon-menu',
          index: '123',
          title: '课程基本信息',
          subs: [
            {
              index: 'basetable',
              title: '作业完成情况'
            },
            {
              index: 'vuetable',
              title: '作业管理'
            }
          ]
        },
        {
          icon: 'el-icon-setting',
          index: '123',
          title: '任课老师'
        },
        {
          icon: 'el-icon-menu',
          index: '4',
          title: '学员管理',
          subs: [
            {
              index: 'basetable',
              title: '学员信息表格'
            },
            {
              index: 'vuetable',
              title: '学员分组管理',
              subs: [
                {
                  index: 'vuetable',
                  title: '分组测试题管理'
                },
                {
                  index: 'vuetable',
                  title: '分组测试考试结果'
                },
                {
                  index: '1234-L',
                  title: '学员智能分组'
                }
              ]
            }
          ]
        },
        {
          icon: 'el-icon-setting',
          index: 'Course',
          title: '授课管理计划'
        },
        {
          icon: 'el-icon-setting',
          index: '02-1',
          title: '评审管理'
        },
        {
          icon: 'el-icon-menu',
          index: '13',
          title: '成绩管理',
          subs: [
            {
              index: 'basetable',
              title: '奖惩分管理'
            },
            {
              index: 'vuetable',
              title: '学员成绩比例'
            },
            {
              index: 'basetable',
              title: '学员成绩报告'
            },
            {
              index: 'vuetable',
              title: '团队总成绩报告'
            },
            {
              index: 'vuetable',
              title: '个人总成绩报告'
            }
          ]
        }
      ]
    }
  },
  computed: {
    onRoutes () {
      return this.$route.path.replace('/', ' ')
    }
  }
}
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  width: 200px;
  height: calc(100vh - 60px);
  color: #c0c5cc;
}
.sidebar > ul {
  height: 100%;
}
.el-menu-vertical-demo{
  float: left;
  width: 100%;
}
.menu-left{
  float: left;
}
</style>
